package cn.com.websocket.util;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;

/***
 ** @category 请用一句话描述这个类的用途
 ** @author qing.yunhui
 ** @email: qingyh@glodon.com
 ** @createTime: 2021-08-18 11:32
 **/
public class StringUtil {

    /**
     * <p>判断给定的字符是否为null或空</p>
     * @param obj
     * @return boolean
     * */
    public static boolean isEmpty(Object obj){
        if(null==obj){
            return true;
        }
        if(obj instanceof Map){
            if(((Map)obj).isEmpty()){
                return true;
            }
        }else if(obj instanceof Collection){
            if(((Collection)obj).isEmpty()){
                return true;
            }
        } else if(obj instanceof String){
            if(((String)obj).trim().length()==0){
                return true;
            }
            if("[]".equals(obj)){
                return true;
            }
        }else if(obj.getClass().isArray()){
            if(Array.getLength(obj)==0){
                return true;
            }
        }
        return false;
    }
    public static boolean isEmptys(Object ...objects){
        for(Object obj:objects){
            boolean empty = isEmpty(obj);
            if(empty){ return Boolean.TRUE; }
        }
        return Boolean.FALSE;
    }

    public static boolean isNotEmpty(Object objects){
        return !isEmpty(objects);
    }

}
